package PA::parser;

use strict;
use warnings;
use lib '/home/homer/ju/jussimik/.laka/pokeralyzer/';
use File::Slurp;
use PA::dbwrap;

my $dbh = PA::dbwrap::get_dbh();

sub parser {
	my($hand_history, $linestart) = @_;
	my @rawfile = read_file($hand_history);
	if($linestart > 0) {
		@rawfile = @rawfile[$linestart..$#rawfile];
	}
	# write something to identify poker site,
	# currently just pokerstars
	my $poker_site = 'ps';

	my $sth = $dbh->prepare('SELECT regex FROM regex ORDER BY id ASC');
	$sth->execute();
	my $regexs_ref = $sth->fetchall_arrayref();

	for my $regex (@{$regexs_ref}) {	
		LINE: for (@rawfile) {
			/@$regex/ && do {
				process_data(get_ident(@$regex, $poker_site));
				next LINE;
			};
		}
	}
}

sub get_ident {
	my($regex, $poker_site) = @_;
	my $sth = $dbh->prepare(
		"SELECT ident FROM regex WHERE regex=? AND site=?"
	);
	$sth->execute($regex, $poker_site);
	
	return $sth->fetchrow_array();
}

sub get_hand_history {

}

sub process_data {
	print join("\n", @_);
}

parser('../hh/ps-hh-sample.txt', 0);	
